import MyModal from "@/components/MyModal";
import { useBoolean, useRequest } from "ahooks";
import { Button, Form, Input, Result } from "antd";
import { checkOrderStatus } from "@/services/customer/customer";
import { message } from "antd";
import { useEffect, useState } from "react";
import dayjs from "dayjs";
export default ({ open, close, refresh }) => {
    const [form] = Form.useForm();
    const [isInfoPage, setIsInfoPage] = useState(true);
    const { data, run, loading } = useRequest(checkOrderStatus, {
        manual: true,
        onSuccess: (res) => {
            message.success(res)
            form.resetFields();
            refresh()
            setIsInfoPage(true)
        }
    })
    useEffect(() => {
        isInfoPage && setIsInfoPage(false)
    }, [open])
    return (
        <>
            {
                isInfoPage ? <MyModal
                    title={"订单信息"}
                    open={open}
                    close={close}
                    footer={null}
                >
                    <Result
                        style={{padding:'12px'}}
                        status="success"
                        title="核验订单成功!"
                        subTitle={
                            <div style={{ display: 'flex', flexDirection: 'column', textAlign: 'left', alignItems: 'center' }}>
                                <span>客户姓名:{data?.name || '某某某'}</span>
                                <span>房间号:{data?.roomNum || 'xxx'}</span>
                                <span>总金额:{data?.houseCosts || '0'}元</span>
                                <span>入住时间:{`${dayjs(data?.stayTime).format("YYYY-MM-DD") || ''}`}</span>
                                <span>退房时间:{`${dayjs(data?.checkoutTime).format("YYYY-MM-DD") || ''}`}</span>
                            </div>
                        }
                    />

                </MyModal> : <MyModal
                    title={"核验订单"}
                    open={open}
                    close={close}
                    onOk={async () => {
                        const formVal = await form.validateFields();
                        run(formVal.orderNo)
                    }}
                    confirmLoading={loading}
                >
                    <Form form={form} wrapperCol={{ span: 24 }} layout="vertical">
                        <Form.Item
                            name="orderNo"
                            rules={[
                                {
                                    required: true,
                                },
                            ]}
                            label="订单号"
                        >
                            <Input placeholder="请输入" />
                        </Form.Item>
                    </Form>

                </MyModal>
            }
        </>
    );
};
